package com.ruoyi.ies.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ies.domain.GarbageStation;
import com.ruoyi.ies.service.IGarbageStationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 垃圾站Controller
 *
 * @author July
 * @date 2023-06-15
 */
@RestController
@RequestMapping("/ies/station")
public class GarbageStationController extends BaseController
{
    @Autowired
    private IGarbageStationService garbageStationService;

    /**
     * 查询垃圾站列表
     */
    @PreAuthorize("@ss.hasPermi('ies:station:list')")
    @GetMapping("/list")
    public TableDataInfo list(GarbageStation garbageStation)
    {
        startPage();
        List<GarbageStation> list = garbageStationService.selectGarbageStationList(garbageStation);
        return getDataTable(list);
    }

    /**
     * 导出垃圾站列表
     */
    @PreAuthorize("@ss.hasPermi('ies:station:export')")
    @Log(title = "垃圾站", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GarbageStation garbageStation)
    {
        List<GarbageStation> list = garbageStationService.selectGarbageStationList(garbageStation);
        ExcelUtil<GarbageStation> util = new ExcelUtil<GarbageStation>(GarbageStation.class);
        util.exportExcel(response, list, "垃圾站数据");
    }

    /**
     * 获取垃圾站详细信息
     */
    @PreAuthorize("@ss.hasPermi('ies:station:query')")
    @GetMapping(value = "/{gId}")
    public AjaxResult getInfo(@PathVariable("gId") Long gId)
    {
        return success(garbageStationService.selectGarbageStationByGId(gId));
    }

    /**
     * 新增垃圾站
     */
    @PreAuthorize("@ss.hasPermi('ies:station:add')")
    @Log(title = "垃圾站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GarbageStation garbageStation)
    {
        return toAjax(garbageStationService.insertGarbageStation(garbageStation));
    }

    /**
     * 修改垃圾站
     */
    @PreAuthorize("@ss.hasPermi('ies:station:edit')")
    @Log(title = "垃圾站", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GarbageStation garbageStation)
    {
        return toAjax(garbageStationService.updateGarbageStation(garbageStation));
    }

    /**
     * 删除垃圾站
     */
    @PreAuthorize("@ss.hasPermi('ies:station:remove')")
    @Log(title = "垃圾站", businessType = BusinessType.DELETE)
    @DeleteMapping("/{gIds}")
    public AjaxResult remove(@PathVariable Long[] gIds)
    {
        return toAjax(garbageStationService.deleteGarbageStationByGIds(gIds));
    }
}
